package com.codecentric.sample.store.service;

import org.springframework.stereotype.Service;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service
public class PassWordService {
    public String CheckPassword(String pwd){
        if(pwd==null||pwd==""){
            return "密码为空";
        }
        int count=0;
        String regex=".*[a-z]+.*";
        Matcher m= Pattern.compile(regex).matcher(pwd);
        String regex1=".*[A-Z]+.*";
        Matcher m1= Pattern.compile(regex1).matcher(pwd);
        String regex2=".*[0-9]+.*";
        Matcher m2= Pattern.compile(regex2).matcher(pwd);
        String regEx3 = ".*[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]+.*";
        Pattern p = Pattern.compile(regEx3);
        Matcher m3 = p.matcher(pwd);
        if(m.matches()){
            count++;
        }
        if(m1.matches()){
            count++;
        }
        if(m2.matches()){
            count++;
        }if (m3.matches()){
            count++;
        }
        if(pwd.length()>8){
            count++;
        }
        String re;
        switch (count){

            case 0:
            case 1:
            case 2:
            case 3:
                re= "弱密码";
                break;
            case 4:
                re="中强密码";
                break;
            case 5:
                re= "强密码";
                break;
            default:
                re="异常";
                break;
        }
        return re;
    }

}
